Various types of storage mechanisms are used to store a XML document. One type of storage mechanism stores a XML document as a text file in a file system. Another type of mechanism for storing XML documents is a database server. In a database server, a XML document may be stored in a row of a table and nodes of the XML document are stored in separate columns in the row. An entire XML document may also be stored in a lob (large object) in a column. A XML document may also be stored as a hierarchy of objects in a database; each object is an instance of an object class and stores one or more elements of a XML document. Tables and/or objects of a database system that hold XML values are referred to herein as base tables or objects.
Such database servers include many mechanisms that allow for powerful and efficient ways to query large collections of XML documents. Database servers that store XML documents may be enhanced to efficiently perform XML operations using these mechanisms. One such type of XML operation is to execute queries over collections of XML documents using XML query languages, such as XQuery/XPath. XML Query Language (“XQuery”) and XML Path Language (“XPath”) are important standards for a query language, which can be used in conjunction with SQL to express a large variety of useful queries. The term XML query is used to refer to queries that conform to (1) XQuery, XPath, and/or another XML language standard, (2) queries including SQL queries that may embed XQuery or XPath expressions, and (3) proprietary dialects of XQuery, XPath, SQL, or XML standard languages. When a database server receives a XML query, the database server may perform a XML rewrite to refer to the underlying base tables and database objects that store the XML data.